﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.ComponentModel;
using System.Collections;

namespace CXMLStudioIDE.Common
{
[Serializable]
public class CBFormCtrlItem
{
    // Fields
    private string ctrlName;
    private string partialName;
    private Hashtable propertyList;

    // Methods
    public CBFormCtrlItem()
    {
        this.propertyList = new Hashtable();
        this.ctrlName = "";
        this.partialName = "";
    }

    public CBFormCtrlItem(object ctrl)
    {
        this.propertyList = new Hashtable();
        this.CtrlName = ctrl.GetType().Name;
        this.PartialName = ctrl.GetType().Namespace;
        foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(ctrl))
        {
            try
            {
                if (!descriptor.PropertyType.IsArray)
                {
                    if (descriptor.PropertyType.IsSerializable)
                    {
                        this.propertyList.Add(descriptor.Name, descriptor.GetValue(ctrl));
                    }
                }
                else
                {
                    Array array = descriptor.GetValue(ctrl) as Array;
                    if ((array.Length > 0) && array.GetValue(0).GetType().IsSerializable)
                    {
                        this.propertyList.Add(descriptor.Name, descriptor.GetValue(ctrl));
                    }
                }
                continue;
            }
            catch (Exception exception)
            {
                Trace.WriteLine(exception.Message);
                continue;
            }
        }
    }

    // Properties
    public string CtrlName
    {
        get
        {
            return this.ctrlName;
        }
        set
        {
            this.ctrlName = value;
        }
    }

    public string PartialName
    {
        get
        {
            return this.partialName;
        }
        set
        {
            this.partialName = value;
        }
    }

    public Hashtable PropertyList
    {
        get
        {
            return this.propertyList;
        }
    }
}

 
 

}
